extends Panel

const units_in_day = 6
var unit = 0
var day = 1
const ids= ["late_night", "e. morning", "morning", "midday", "noon", "evening", "night"]

onready var arrow = $HBoxContainer/VBoxContainer/clock/arrow
var arrow_target = 0

func _ready():
	advance(3)

func advance(units):
	var old = unit
	unit = (unit + units) % (units_in_day+1)
	var days_plus = int((old+units) / (units_in_day+1))
	day += days_plus
	var unit_rot = ((PI+PI) / float(units_in_day))
	arrow_target = ((unit_rot) * (float(unit))) - (unit_rot*0.5)
	$HBoxContainer/VBoxContainer2/day.text = "Day " + str(day)
	$HBoxContainer/VBoxContainer/time.text = ids[unit]

func _process(delta):
	var diff = 0.5 * delta
	var new_value = arrow.get_rotation() + diff
	if new_value > arrow_target:
		arrow.set_rotation(arrow_target)
	else:
		arrow.set_rotation(new_value)

func on_money_changed(new, old, diff):
	$HBoxContainer/VBoxContainer2/money.text = "$" + str(new)
